<script src="http://unpkg.com/vue"></script>
<div id="app"></div>
<script>
  const { createApp, ref, onUnmounted, onMounted } = Vue;
  const useMouse = () => {
    const x = ref(0);
    const y = ref(0);
    const update = (e) => {
      x.value = e.clientX;
      y.value = e.clientY;
    };
    onMounted(() => {
      window.addEventListener("mousemove", update);
    });
    onUnmounted(() => {
      window.removeEventListener("mousemove", update);
    });
    return { x, y };
  };
  const App = {
    template: `{{x}} {{y}}`,
    setup() {
      // 可以在此处修改引入的变量名
      let { x, y } = useMouse();
      return { x, y };
    },
  };
  createApp(App).mount("#app");
</script>
